import storage from 'common/cache'

const USER_KEY = '__user__'
const USER_INFO_KEY = '__user_info__'
const TOKEN_KEY = '__token__'
const REFRESH_TOKEN_KEY = '__refresh_token__'

export function saveUserSimple(user) {
	storage.session.set(USER_KEY,user)
	return user
}

export function getUserSimple() {
	return storage.session.get(USER_KEY) || {}
}

export function saveUserComplex(user) {
	storage.session.set(USER_INFO_KEY,user)
	return user
}

export function getUserComplex() {
	return storage.session.get(USER_INFO_KEY) || {}
}

export function saveTokenInfo(token) {
	storage.session.set(TOKEN_KEY, token)
	return token
}

export function getTokenInfo() {
	return storage.session.get(TOKEN_KEY) || {}
}

export function cleanStorage(type='session') {
	if(type==='session') {
		storage.session.clear()
		return true
	}
	storage.session.clear()
	storage.clear()
	return true
}

export function saveRefreshToken(token) {
	storage.set(REFRESH_TOKEN_KEY, token)
}

export function getRefreshToken() {
	return storage.get(REFRESH_TOKEN_KEY)
}

export function removeRefreshToken() {
	storage.remove(REFRESH_TOKEN_KEY)
}